home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13667 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: in-news.erinet.com!usenet
  2. From: timb@erinet.com (Tim Berens)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: my program has a mind of its own (no really)
  5. Date: Tue, 09 Apr 1996 21:12:02 GMT
  6. Organization: EriNet Online 513 436-9915
  7. Message-ID: <4ke9d2$eqp@eri.erinet.com>
  8. References: <sbb-0904960305370001@ts13-06.upenn.edu>
  9. NNTP-Posting-Host: dlp3.ctrvl.eri.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. sbb@eniac.seas.upenn.edu (Steve Bronstein) wrote:
  13.  
  14. >I am writing a program (with cc as compiler) which has a number of arrays,
  15. >which I have been verry careful to initialize with values, to avoid
  16. >segmentation faults. The main part of the program is a loop beginning with
  17. >an fgets statement to read in the next line from a file. Under certain
  18. >circumstances, the program returns "Segmentation Fault" just as it reaches
  19. >the beginning of this loop. When I put it a printf statement right before
  20. >the loop to see how far it actually got, it worked. 
  21.  
  22. >printf("something\n");
  23.  
  24. >When I removed "something", leaving just
  25.  
  26. >printf("\n");
  27.  
  28. >it gave me a segmentation fault again. I tried the same tactic at the
  29. >beginning of the loop, and found that the program worked with a long word
  30. >in the printf statement, but not a short word. Needless to say, I am
  31. >slightly bewildered by this behavior, as the printf statement, at least to
  32. >my knowledge, has no effect on my arrrays. If anyone has had a similar
  33. >experience, or knows what's going on here, I'd be extremely grateful.
  34.  
  35. >Thanks,
  36.  
  37. >Steve Bronstein
  38. >http://www.seas.upenn.edu/~sbb
  39.  
  40. There's a commercial  product called memcheck which can be invaluable
  41. in tracking down this type of problem.  I had a nasty little problem
  42. that was in a system I was developing.  It was buried somewhere in
  43. about 50,000 lines of code, and occasionally caused UNIX to dump core.
  44. Classic pointer problem symptoms.
  45.  
  46. Since I was on a very tight deadline and knew how long this kind of
  47. problem can take to track down, I ordered memcheck.   It took about an
  48. hour to install and get it compiled into my code.  It pointed me to
  49. the exact line of code causing the problem the first time I ran the
  50. program.  No joke.  I know I sound like somebody on the Home Shopping
  51. Network, but it really worked wonders.  I never fly without it now.
  52.  
  53. Disclaimer:  I have no connection to the company that makes memcheck.
  54. If you are interested in the product, look up their ads in Dr. Dobb's
  55. or C User's Journal.  The company name is StratosWare.
  56.  
  57. Tim Berens
  58.  
  59.